package com.hongyue.kafka.controller;

import com.alibaba.fastjson.JSON;
import com.hongyue.kafka.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping
public class HelloController {

    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;

    private static final String TOPIC = "input_topic";

    @GetMapping("/hello")
    public String hello() {

//        User user = new User(1, "小明", 21);

        for (int i = 0; i < 10; i++) {
            kafkaTemplate.send(TOPIC, "helloworld kafka stream");
        }
        return "发送成功";
    }
}
